<?php
include("../pages/config.php");
###---  This file is ued for querying the Metaswitch for information

$directoryNumber = $_GET['queryString'];
$debug = $_GET['debug'];
$cmd = $_GET['cmd'];
$pin = $_GET['pin'];
$longDistanceCarrier = $_GET['longDistanceCarrier'];
$intraLATACarrier = $_GET['intraLATACarrier'];
$internationalCarrier = $_GET['internationalCarrier'];

function format_phone($phone)
{
	$phone = preg_replace("/[^0-9]/", "", $phone);
      
	if(strlen($phone) == 7){
      		return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
	}
      	elseif(strlen($phone) == 10) {
      		return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
	}
      	else{
      		return $phone;
	}
}

$client = new SoapClient('sdk/xml/soap/ShServiceTyped.wsdl');

//  This section creates the parameters to pass to the Meta for a Pull (Query)
$params = array(
		'UserIdentity' => $directoryNumber,
		'DataReference' => 0,
		//'ServiceIndication' => 'Meta_Subscriber_BaseInformation',
		'ServiceIndication' => 'Meta_Subscriber_*',
		'OriginHost' => 'amherst.com?clientVersion=7.0'
		);

//  Send the Pull (Query) to the Meta and put the returned results into $resultCode
$resultCode = $client->ShPull($params);

if ($debug == "True") {
	echo "<pre>";
	print_r($resultCode);
	echo "</pre>";
}

//  If the result returns a failure, echo the result detail to the screen and stop
if ($resultCode->{'ResultCode'} == "5001") {
	echo $resultCode->{'ExtendedResult'}->{'ExtendedResultDetail'};
}
else {
	//  $Meta_Sub_Base is put in place, so we don't have to keep repeating this for each of the results below
	//  When using the "wildcard" character to return multiple results, RepositoryData is an array NOT a stdClass obj
	//$Meta_Sub_Base = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_BaseInformation'};

	// META changed the structure of the results returned in 7.1.  Now we look to see if service indication is at position 27 (SIP) or 31 (POTS)
	
	$Meta_Sub_Base27 = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[27]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_BaseInformation'};
	$Meta_Sub_Base31 = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[31]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_BaseInformation'};

	if ($Meta_Sub_Base27->{'CallAgentSignalingType'} == 'SIP') {
		$Meta_Sub_Base = $Meta_Sub_Base27;
		$Meta_Sub_LineClassCodes = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[29]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_LineClassCodes'};
		$Meta_Sub_MissedCalls = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[33]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallLists'}->{'MissedCalls'};	
		$Meta_Sub_DialedCalls = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[33]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallLists'}->{'DialedCalls'};	
		$Meta_Sub_LastIncomingCall = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[34]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_LastIncomingCall'};	
		$Meta_Sub_LastOutgoingCall = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[35]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_LastOutgoingCall'};	
		$Meta_Sub_CallingNumberDelivery = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[3]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallingNumberDelivery'};	
		$Meta_Sub_CallingNameDelivery = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[6]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallingNameDelivery'};	
		$Meta_Sub_CallingNameAndNumberDeliveryOverIP = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[7]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallingNameAndNumberDeliveryOverIP'};	
		$Meta_Sub_Voicemail = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[65]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_Voicemail'};	
		$Meta_Sub_CallWaiting = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[22]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallWaiting'};	
		$Meta_Sub_CallWaitingWithCallerID = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[23]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallWaitingWithCallerID'};	
		$Meta_Sub_AnonymousCallRejection = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[50]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_AnonymousCallRejection'};	
		$Meta_Sub_CallBarring = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[61]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallBarring'};	
		$CurrentSubscriberBarredCallTypes = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[61]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallBarring'}->{'CurrentSubscriberBarredCallTypes'};	
	}
	else if ($Meta_Sub_Base31->{'CallAgentSignalingType'} == 'Analog Line/T1 CAS') {
		$Meta_Sub_Base = $Meta_Sub_Base31;
		$Meta_Sub_LineClassCodes = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[33]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_LineClassCodes'};
		$Meta_Sub_MissedCalls = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[37]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallLists'}->{'MissedCalls'};	
		$Meta_Sub_DialedCalls = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[37]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallLists'}->{'DialedCalls'};	
		$Meta_Sub_LastIncomingCall = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[38]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_LastIncomingCall'};	
		$Meta_Sub_LastOutgoingCall = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[39]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_LastOutgoingCall'};	
		$Meta_Sub_CallingNumberDelivery = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[3]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallingNumberDelivery'};	
		$Meta_Sub_CallingNameDelivery = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[6]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallingNameDelivery'};	
		$Meta_Sub_CallingNameAndNumberDeliveryOverIP = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[7]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallingNameAndNumberDeliveryOverIP'};	
		$Meta_Sub_Voicemail = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[68]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_Voicemail'};	
		$Meta_Sub_CallWaiting = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[26]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallWaiting'};	
		$Meta_Sub_CallWaitingWithCallerID = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[27]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallWaitingWithCallerID'};	
		$Meta_Sub_AnonymousCallRejection = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[54]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_AnonymousCallRejection'};	
		$Meta_Sub_CallBarring = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[65]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallBarring'};	
		$CurrentSubscriberBarredCallTypes = $resultCode->{'UserData'}->{'Sh-Data'}->{'RepositoryData'}[65]->{'ServiceData'}->{'MetaSwitchData'}->{'Meta_Subscriber_CallBarring'}->{'CurrentSubscriberBarredCallTypes'};	
	}
	else {
		echo "Unable to determine CallAgentSignalingType<br/>";
	}

	if ($cmd == 'meta_update_sub') {
		//  if the cmd submitted is for edit sub, then return a form with editable fields
		echo "<table><tr><td valign='top'>";
		echo "<form>";
		echo "<table class='results'>";
		echo "<tr class='results' style='background: #e6e6e6'><th colspan='2' style='border-bottom: solid 1px #b5b5b5'>Base Information</th></tr>";
		echo "<tr><td>Subscriber Type: </td><td><input type=\"text\" value=\"" . $Meta_Sub_Base->{'SubscriberType'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Directory Number: </td><td><input id=\"directoryNumber\" type=\"text\" value=\"" . $Meta_Sub_Base->{'DirectoryNumber'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Persistent Profile: </td><td><input type=\"text\" value=\"" . $Meta_Sub_Base->{'PersistentProfile'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Subscriber Group: </td><td><input type=\"text\" value=\"" . $Meta_Sub_Base->{'SubscriberGroup'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Signaling Type: </td><td><input id=\"callAgentSignalingType\" type=\"text\" value=\"" . $Meta_Sub_Base->{'CallAgentSignalingType'} . "\" readonly='readonly'/></td></tr>";
		if (!empty($Meta_Sub_Base->{'AccessDevice'})) {
			echo "<tr><td>Gateway Name: </td><td><input id=\"gatewayName\" type=\"text\" value=\"" . $Meta_Sub_Base->{'AccessDevice'}->{'GatewayName'} . "\" /></td></tr>";
			echo "<tr><td>Access Device Name: </td><td><input id=\"accessDeviceName\" type=\"text\" value=\"" . $Meta_Sub_Base->{'AccessDevice'}->{'AccessDeviceName'} . "\" /></td></tr>";
			echo "<tr><td>Access Line Number: </td><td><input id=\"accessLineNumber\" type=\"text\" value=\"" . $Meta_Sub_Base->{'AccessLineNumber'} . "\" /></td></tr>";
		}
		echo "<tr><td>Long Distance Carrier: </td><td><input id=\"longDistanceCarrier\" type=\"text\" maxlength=\"4\"value=\"" . $Meta_Sub_Base->{'LongDistanceCarrier'}->{'Value'} . "\" /></td></tr>";
		echo "<tr><td>IntraLATA Carrier: </td><td><input id=\"intraLATACarrier\" type=\"text\" maxlength=\"4\"value=\"" . $Meta_Sub_Base->{'IntraLATACarrier'}->{'Value'} . "\" /></td></tr>";
		echo "<tr><td>International Carrier: </td><td><input id=\"internationalCarrier\" maxlength=\"4\"type=\"text\" value=\"" . $Meta_Sub_Base->{'InternationalCarrier'}->{'Value'} . "\" /></td></tr>";
		echo "<tr><td>PIN: </td><td><input id=\"PIN\" type=\"text\" maxlength=\"4\" value=\"" . $Meta_Sub_Base->{'PIN'} . "\" /></td></tr>";
		echo "<tr><td>Billing Type: </td><td><input type=\"text\" value=\"" . $Meta_Sub_Base->{'BillingType'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Service Status: </td><td><select id=\"serviceStatus\">";
				if ($Meta_Sub_Base->{'ServiceSuspended'} == "None") {
					echo "<option value=\"None\" selected=\"yes\">Active</option>";
					echo "<option value=\"Incoming and Outgoing calls\">Suspended</option>";
				}
				else {
					echo "<option value=\"None\">Active</option>";
					echo "<option value=\"Incoming and Outgoing calls\" selected=\"yes\">Suspended</option>";

				}	
				
		echo "</select></td></tr>";
		echo "</table>";
		echo "<input type=\"reset\" value=\"Reset\" /><input type=\"button\" value=\"Update\" onClick=\"submit_update(document.getElementById('directoryNumber').value)\"/><input type=\"checkbox\" id=\"baseDebug\" value=\"True\"/>";
		echo "</form>";
		echo "</td><td valign='top'>";
		echo "<form>";
		echo "<table class='results'>";
		echo "<tr style='background: #e6e6e6'><th colspan='2' style='border-top: solid 1px #b5b5b5; border-bottom: solid 1px #b5b5b5'>Features:</th></tr>";
		echo "<tr><td>Caller Name: </td><td><select onChange=\"update_callername(document.getElementById('directoryNumber').value)\" id=\"callerName\">";
				if ($Meta_Sub_CallingNameDelivery->{'Subscribed'}->{'Value'} == "True") {
					echo "<option value='True' selected='yes'>True</option>";
					echo "<option value='False'>False</option>";
				}
				else {
					echo "<option value='True'>True</option>";
					echo "<option value='False' selected='yes'>False</option>";
				}
		echo "</select></td></tr>";
		echo "<tr><td>Caller Number: </td><td><select onChange=\"update_callernumber(document.getElementById('directoryNumber').value)\" id=\"callerNumber\">";
				if ($Meta_Sub_CallingNumberDelivery->{'Subscribed'}->{'Value'} == "True") {
					echo "<option value='True' selected='yes'>True</option>";
					echo "<option value='False'>False</option>";
				}
				else {
					echo "<option value='True'>True</option>";
					echo "<option value='False' selected='yes'>False</option>";
				}
		echo "</select></td></tr>";
		echo "<tr><td>Voicemail: </td><td><select onChange=\"update_voicemail(document.getElementById('directoryNumber').value)\" id=\"voicemail\">";
				if ($Meta_Sub_Voicemail->{'Subscribed'}->{'Value'} == "True") {
					echo "<option value='True' selected='yes'>True</option>";
					echo "<option value='False'>False</option>";
				}
				else {
					echo "<option value='True'>True</option>";
					echo "<option value='False' selected='yes'>False</option>";
				}
		echo "</select></td></tr>";
		//  If the subscriber does not have voicemail, then don't display the CFRC option
		if ($Meta_Sub_Voicemail->{'Subscribed'}->{'Value'} == "True") {
			echo "<tr><td>CFRC: </td><td><select onChange=\"update_voicemail_cfrc(document.getElementById('directoryNumber').value)\" id=\"cfrc\">";
				$cfrc = $Meta_Sub_Voicemail->{'CallTransferTime'}->{'Value'};
				for ($i = 3; $i <= 10; $i++) {
					echo "<option value='" . $i*6 . "' ";
					if ($cfrc/6 == $i) {
						echo "selected='yes'";
					}
					echo ">$i</option>";
				}
			echo "</select></td></tr>";
		}
		//  If the subscriber signal type is SIP, then there is no CallWaiting or CallWaitingWithCallerID
		if ($Meta_Sub_Base->{'CallAgentSignalingType'} == "Analog Line/T1 CAS") {
			echo "<tr><td>Call Waiting: </td><td><select onChange=\"update_callwaiting(document.getElementById('directoryNumber').value)\" id=\"callWaiting\">";
				if ($Meta_Sub_CallWaiting->{'Subscribed'}->{'Value'} == "True") {
					echo "<option value='True' selected='yes'>True</option>";
					echo "<option value='False'>False</option>";
				}
				else {
					echo "<option value='True'>True</option>";
					echo "<option value='False' selected='yes'>False</option>";
				}
			echo "</select></td></tr>";
			echo "<tr><td>Call Waiting w/ Caller ID: </td><td><select onChange=\"update_callwaitingwithcallerID(document.getElementById('directoryNumber').value)\" id=\"callWaitingWithCallerID\">";
				if ($Meta_Sub_CallWaitingWithCallerID->{'Subscribed'}->{'Value'} == "True") {
					echo "<option value='True' selected='yes'>True</option>";
					echo "<option value='False'>False</option>";
				}
				else {
					echo "<option value='True'>True</option>";
					echo "<option value='False' selected='yes'>False</option>";
				}
			echo "</select></td></tr>";
		}
		echo "<tr><td>Anonymous Call Rejection: </td><td><select onChange=\"update_anonymouscallrejection(document.getElementById('directoryNumber').value)\" id=\"anonymousCallRejection\">";
				if ($Meta_Sub_AnonymousCallRejection->{'Subscribed'}->{'Value'} == "True") {
					echo "<option value='True' selected='yes'>True</option>";
					echo "<option value='False'>False</option>";
				}
				else {
					echo "<option value='True'>True</option>";
					echo "<option value='False' selected='yes'>False</option>";
				}
		echo "</select></td></tr>";
		echo "<tr><td>Screenpop: </td><td><select onChange=\"update_screenpop(document.getElementById('directoryNumber').value)\" id=\"screenpop\" >";
				if ($Meta_Sub_CallingNameAndNumberDeliveryOverIP->{'Subscribed'}->{'Value'} == "True") {
					echo "<option value='True' selected='yes'>True</option>";
					echo "<option value='False'>False</option>";
				}
				else {
					echo "<option value='True'>True</option>";
					echo "<option value='False' selected='yes'>False</option>";
				}
		echo "</select></td></tr>";
		echo "<tr><td>Block International Calls: </td><td><select id='InternationalBarredCallType' onChange=\"update_barredcalltypes(document.getElementById('directoryNumber').value, 'International')\">";
			if ($CurrentSubscriberBarredCallTypes->{'Value'}->{'International'}->{'_'} == "True") {
				echo "<option value='True' selected='yes'>True</option>";
				echo "<option value='False'>False</option>";
			}
			else {
				echo "<option value='True'>True</option>";
				echo "<option value='False' selected='yes'>False</option>";
			}
		echo "</select></td></tr>";
		echo "<tr><td>Block 900 Calls: </td><td><select id='PremiumBarredCallType' onChange=\"update_barredcalltypes(document.getElementById('directoryNumber').value, 'Premium')\">";
			if ($CurrentSubscriberBarredCallTypes->{'Value'}->{'Premium'}->{'_'} == "True") {
				echo "<option value='True' selected='yes'>True</option>";
				echo "<option value='False'>False</option>";
			}
			else {
				echo "<option value='True'>True</option>";
				echo "<option value='False' selected='yes'>False</option>";
			}
		echo "</select></td></tr>";
		echo "<tr><td>Block Operator Calls: </td><td><select id='OperatorBarredCallType' onChange=\"update_barredcalltypes(document.getElementById('directoryNumber').value, 'Operator')\">";
			if ($CurrentSubscriberBarredCallTypes->{'Value'}->{'Operator'}->{'_'} == "True") {
				echo "<option value='True' selected='yes'>True</option>";
				echo "<option value='False'>False</option>";
			}
			else {
				echo "<option value='True'>True</option>";
				echo "<option value='False' selected='yes'>False</option>";
			}
		echo "</select></td></tr>";
		echo "<tr><td>Block Directory Assistance Calls: </td><td><select id='DirectoryAssistanceBarredCallType' onChange=\"update_barredcalltypes(document.getElementById('directoryNumber').value, 'DirectoryAssistance')\">";
			if ($CurrentSubscriberBarredCallTypes->{'Value'}->{'DirectoryAssistance'}->{'_'} == "True") {
				echo "<option value='True' selected='yes'>True</option>";
				echo "<option value='False'>False</option>";
			}
			else {
				echo "<option value='True'>True</option>";
				echo "<option value='False' selected='yes'>False</option>";
			}
		echo "</select></td></tr>";
		echo "</table>";
		echo "<input type=\"checkbox\" id=\"featuresDebug\" value=\"True\"/>";
		//echo "<input type=\"reset\" value=\"Reset\" /><input type=\"button\" value=\"Update\" onClick=\"update_features(document.getElementById('directoryNumber').value)\"/><input type=\"checkbox\" id=\"featuresDebug\" value=\"True\"/>";
		echo "</form>";
		echo "</td>";
		echo "</tr></table>";

	}
	else {
		//echo "<table class='results' style='border: solid 1px #b5b5b5'>";
		echo "<table><tr><td>";
		echo "<table class='results'>";
		echo "<tr class='results' style='background: #e6e6e6'><th colspan='2' style='border-bottom: solid 1px #b5b5b5'>Base Information</th></tr>";
		echo "<tr><td>Subscriber Type: </td><td><input type=\"text\" value=\"" . $Meta_Sub_Base->{'SubscriberType'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Directory Number: </td><td><input type=\"text\" value=\"" . $Meta_Sub_Base->{'DirectoryNumber'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Persistent Profile: </td><td><input type=\"text\" value=\"" . $Meta_Sub_Base->{'PersistentProfile'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Subscriber Group: </td><td><input type=\"text\" value=\"" . $Meta_Sub_Base->{'SubscriberGroup'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Signaling Type: </td><td><input id=\"signalingType\" type=\"text\" value=\"" . $Meta_Sub_Base->{'CallAgentSignalingType'} . "\" readonly='readonly'/></td></tr>";
		if (!empty($Meta_Sub_Base->{'AccessDevice'})) {
			echo "<tr><td>Gateway Name: </td><td><input id=\"gatewayName\" type=\"text\" value=\"" . $Meta_Sub_Base->{'AccessDevice'}->{'GatewayName'} . "\" readonly='readonly'/></td></tr>";
			echo "<tr><td>Access Device Name: </td><td><input id=\"accessDeviceName\" type=\"text\" value=\"" . $Meta_Sub_Base->{'AccessDevice'}->{'AccessDeviceName'} . "\" readonly='readonly'/></td></tr>";
			echo "<tr><td>Access Line Number: </td><td><input id=\"accessDeviceName\" type=\"text\" value=\"" . $Meta_Sub_Base->{'AccessLineNumber'} . "\" readonly='readonly'/></td></tr>";
		}
		echo "<tr><td>Long Distance Carrier: </td><td><input id=\"longDistanceCarrier\" type=\"text\" value=\"" . $Meta_Sub_Base->{'LongDistanceCarrier'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>IntraLATA Carrier: </td><td><input id=\"IntraLATACarrier\" type=\"text\" value=\"" . $Meta_Sub_Base->{'IntraLATACarrier'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>International Carrier: </td><td><input id=\"InternationalCarrier\" type=\"text\" value=\"" . $Meta_Sub_Base->{'InternationalCarrier'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>PIN: </td><td><input id=\"PIN\" type=\"text\" value=\"" . $Meta_Sub_Base->{'PIN'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Billing Type: </td><td><input type=\"text\" value=\"" . $Meta_Sub_Base->{'BillingType'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>LCC 1: </td><td><input id=\"lineClassCode1\" type=\"text\" value=\"" . $Meta_Sub_LineClassCodes->{'LineClassCode1'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>LCC 2: </td><td><input id=\"lineClassCode2\" type=\"text\" value=\"" . $Meta_Sub_LineClassCodes->{'LineClassCode2'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>LCC 3: </td><td><input id=\"lineClassCode3\" type=\"text\" value=\"" . $Meta_Sub_LineClassCodes->{'LineClassCode3'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>LCC 4: </td><td><input id=\"lineClassCode4\" type=\"text\" value=\"" . $Meta_Sub_LineClassCodes->{'LineClassCode4'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>LCC 5: </td><td><input id=\"lineClassCode5\" type=\"text\" value=\"" . $Meta_Sub_LineClassCodes->{'LineClassCode5'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Service Status: </td><td><input id=\"serviceStatus\" type=\"text\" value=\"" . $Meta_Sub_Base->{'ServiceSuspended'} . "\" readonly='readonly'/></td></tr>";
		echo "</table>";
		echo "</td><td valign='top'>";
		echo "<table class='results'>";
		echo "<tr style='background: #e6e6e6'><th colspan='2' style='border-top: solid 1px #b5b5b5; border-bottom: solid 1px #b5b5b5'>Features:</th></tr>";
		echo "<tr><td>Caller Name: </td><td><input id=\"callerName\" type=\"text\" value=\"" . $Meta_Sub_CallingNameDelivery->{'Subscribed'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Caller Number: </td><td><input id=\"callerNumber\" type=\"text\" value=\"" . $Meta_Sub_CallingNumberDelivery->{'Subscribed'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Voicemail: </td><td><input id=\"voicemail\" type=\"text\" value=\"" . $Meta_Sub_Voicemail->{'Subscribed'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		//  If the subscriber signal type is SIP, then there is no CallWaiting or CallWaitingWithCallerID
		if ($Meta_Sub_Base->{'CallAgentSignalingType'} == "Analog Line/T1 CAS") {
			echo "<tr><td>Call Waiting: </td><td><input id=\"callWaiting\" type=\"text\" value=\"" . $Meta_Sub_CallWaiting->{'Subscribed'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
			echo "<tr><td>Call Waiting w/ Caller ID: </td><td><input id=\"callWaitingWithCallerID\" type=\"text\" value=\"" . $Meta_Sub_CallWaitingWithCallerID->{'Subscribed'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		}
		echo "<tr><td>Anonymous Call Rejection: </td><td><input id=\"anonCallRejection\" type=\"text\" value=\"" . $Meta_Sub_AnonymousCallRejection->{'Subscribed'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		echo "<tr><td>Screenpop: </td><td><input id=\"screenpop\" type=\"text\" value=\"" . $Meta_Sub_CallingNameAndNumberDeliveryOverIP->{'Subscribed'}->{'Value'} . "\" readonly='readonly'/></td></tr>";
		//if ($Meta_Sub_CallBarring->{'Subscribed'}->{'Value'} == "True") {
			echo "<tr><td valign='top'>Call Barring: </td><td>";
			// Display Call Barring options here but don't allow them to be changed
			// TODO:  try to cleanup this section to make it cleaner
				$International = $CurrentSubscriberBarredCallTypes->{'Value'}->{'International'}->{'_'};
				$NationalAndMobile = $CurrentSubscriberBarredCallTypes->{'Value'}->{'NationalAndMobile'}->{'_'};
				$Local = $CurrentSubscriberBarredCallTypes->{'Value'}->{'Local'}->{'_'};
				$Operator = $CurrentSubscriberBarredCallTypes->{'Value'}->{'Operator'}->{'_'};
				$Premium = $CurrentSubscriberBarredCallTypes->{'Value'}->{'Premium'}->{'_'};

				if ($International == "True") {
                	        	echo "<input type='checkbox' value='$International' disabled='disabled' checked/>International<br/>";
				}
				else {
                	        	echo "<input type='checkbox' value='$International' disabled='disabled'/>International<br/>";
				}
				
				if ($NationalAndMobile == "True") {
                        		echo "<input type='checkbox' value='$NationalAndMobile' disabled='disabled' checked/>NationalAndMobile<br/>";
				}
                        	else {
					echo "<input type='checkbox' value='$NationalAndMobile' disabled='disabled'/>NationalAndMobile<br/>";
				}
				
				if ($Local == "True") {
                        		echo "<input type='checkbox' value='$Local' disabled='disabled' checked/>Local<br/>";        
				}
				else {
                        		echo "<input type='checkbox' value='$Local' disabled='disabled'/>Local<br/>";        
				}
				
				if ($Operator == "True") {
                        		echo "<input type='checkbox' value='$Operator' disabled='disabled' checked/>Operator<br/>";     
				}
				else {
                        		echo "<input type='checkbox' value='$Operator' disabled='disabled'/>Operator<br/>";     
				}

				if ($Premium == "True") {
                        		echo "<input type='checkbox' value='$Premium' disabled='disabled' checked/>Premium<br/>";      
				}
				else {
                        		echo "<input type='checkbox' value='$Premium' disabled='disabled'/>Premium<br/>";      
				}
				
                	echo "</td></tr>";
		//}
		echo "</table>";
		echo "</td><td valign='top'>";
		//  Recent 10 missed calls list "Meta_Subscriber_CallLists"
		echo "<table style='border: solid 1px #b5b5b5; width: 300px;'>";
		echo "<tr style='background: #e6e6e6'><th colspan='2' style='border-bottom: solid 1px #b5b5b5'>Recent Missed Calls</th></tr>";
		echo "<tr><th>Phone Number</th><th>Date</th></tr>";
		foreach ((array) $Meta_Sub_MissedCalls->{'Call'} as $key) {
			echo "<tr><td>" . format_phone($key->{'DirectoryNumber'}) . "</td><td>" . $key->{'DateTime'} . "</td></tr>";
		}
		echo "</table>";
		//  Last Incoming Call
		echo "Last Incoming Call: " . format_phone($Meta_Sub_LastIncomingCall->{'CallingNumber'}) . "<br/>";		
		echo "</td><td valign='top'>";
		//  Recent 10 dialed calls list "Meta_Subscriber_CallLists"
		echo "<table class='results'>";
		echo "<tr style='background: #e6e6e6'><th colspan='3' style='border-bottom: solid 1px #b5b5b5'>Recent Dialed calls</th></tr>";
		echo "<tr><th>Phone Number</th><th>Date</th><th>Duration</th></tr>";
		foreach ((array) $Meta_Sub_DialedCalls->{'Call'} as $key) {
			echo "<tr><td>" . format_phone($key->{'DirectoryNumber'}) . "</td><td>" . $key->{'DateTime'} . "</td><td>" . $key->{'Duration'} . "</td></tr>";
		}
		echo "</table>";
		//  Last Outgoing Call
		echo "Last Outgoing Call: " . format_phone($Meta_Sub_LastOutgoingCall->{'CalledNumber'}) . "<br/>";		
		echo "</td></tr>";
		echo "</table>";
	
		echo "</table>";
	}
}
?>
